/**
 * 商家模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	var merchandiseTypeId="",merchandiseName="",sort="0",pageSize=10,shopName="";
	
	var validate = require("../../custom/base/component-validate.js");
	
	require("../../custom/base/component-core.js");
	
	var base = require("../../custom/base/component-base.js");
	
	base.init(base);
	
	var async = require("../../custom/base/component-async.js");
	
	require("../../custom/base/component-md5.js");
	
	require("../../custom/base/component-page.js");
	
	//分享模块
	require.async(["../../custom/share/module-share.js"], function(share) {
		
		  share.init(share);
	  });

	//设置商家代码
	exports.setShopId=function(shopId){
		
		this.shopId=shopId;
		
	};
	
	//获取商家代码
	exports.getShopId=function(){
		
		return this.shopId;
		
	};
	
	//设置父类型代码
	exports.setParentId=function(parentId){
		
		this.parentId=parentId;
		
		if(validate.isNull(parentId)){
			
			merchandiseTypeId="";
			
			$("#ldhStore .store_neck").removeClass("on");
			
			$("#shopMerchandiseTypeName").html("全部");
			
			exports.setCurrentPage(1);
			
			$("#shopMerchandiseList").html("");
					
			$("#ldhStore .checkmore").hide();
			
			exports.getShopMerchandise();
			
			return;
		}
		
		$("#ldhStore .ui-block-a").css("width","50%");
		
		$("#ldhStore .ui-block-b").css("width","50%");
		
		exports.getShopMerchandiseType();
		
	};
	
	//获取父类型代码
	exports.getParentId=function(){
		
		return this.parentId==null?"":this.parentId;
		
	};
	
	//设置列表页码
	exports.setCurrentPage=function(currentPage){
		
		this.currentPage=currentPage;
		
	};
	
	//获取列表页码
	exports.getCurrentPage=function(){
		
		return this.currentPage==null?1:this.currentPage;
		
	};
	
	
	//初始化函数
	exports.init=function(m){
		
		window.$ldh_shop=m;
		
		base.setFromPage("shopIndex");
		
		

		exports.setShopId(base.getParameter("shopId"));
		
	
		
		//exports.getShopDetail(exports.getShopId());
		
		//exports.getCartNum();
				
	};
	

	//查询商家基本信息
	var scoreAbleFlag=false;
	exports.getShopDetail=function(shopId){
		
		base.showLoading();
		
		var params = {
			userId:base.getCookie("userId"),
			shopId:shopId,
			sign:MD5(shopId)	
		};
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopapp/Shop/queryShopMessage.do", params));

					
							if(data["code"]==1){
								
								
								if(validate.isNull(data["shop"]))
								{
									window.location.href=ctx+"/v1/pages/404.jsp";
									return;
								}
								//{"shop":{"address":"广州市越秀区吉祥路20号 ","agentId":"62730905","bannerUrl":"","businessHours":"10:00-21:3","businessStatus":"1","businessStatusType":"","card":"","certificateaUrl":"","certificatebUrl":"","certificatecUrl":"","certificatedUrl":"","certificateeUrl":"","cityId":"440100","comName":"广州吉祥文化有限公司","contact":"李灵","createName":"201406201557010874","createTime":"2014-06-24 20:50:39","ddpPsw":"","gradeId":"","identityNo":"","identityaUrl":"","identitybUrl":"","identitycUrl":"","introduce":"","latitude":23.106913,"logoUrl":"/shop/201406242050390022/info/14037693407873710640.jpg","longitude":113.319337,"mcc":0,"mccCost":0,"mccSign":0,"memo":"","merchantName":"","merchantNo":"","minAmount":20,"mobile":"400-029-0823","msgMobile":"400-029-0823","notice":"","parentShopId":"201404231800490000001","phone":"400-029-0823","printType":"","provinceId":"440000","range":50000,"rateOffline":0,"rateOnline":0,"recommended":"","regionId":"440104","score":3,"seoWeight":100,"shipTime":1,"shopId":"201406242050390022","shopName":"吉祥小店","shopTypeId":"14","street":"","updateName":"201406201557010874","updateTime":"2015-05-06 19:40:34","url":""},"speId":"1,2","payments":"2","scoreAbleFlag":false,"imageSize":"0","erpShopImgList":[],"orderTypeTotalList":[{"ORDERSTATUSID":"1","ORDERSTATUSNAME":"待发货","NUMS":0},{"ORDERSTATUSID":"2","ORDERSTATUSNAME":"待收货","NUMS":0},{"ORDERSTATUSID":"3","ORDERSTATUSNAME":"交易成功","NUMS":0},{"ORDERSTATUSID":"4","ORDERSTATUSNAME":"交易关闭","NUMS":11},{"ORDERSTATUSID":"5","ORDERSTATUSNAME":"待付款","NUMS":0},{"ORDERSTATUSID":"6","ORDERSTATUSNAME":"拒绝收货","NUMS":0},{"ORDERSTATUSID":"7","ORDERSTATUSNAME":"客服调解","NUMS":0}],"toPayFuwu":"0","toPayOrderId":"","code":"1","message":"调用成功"}

								
								var shopId = data["shop"]["shopId"];
								var shopName = data["shop"]["shopName"];
								var logoUrl = data["shop"]["logoUrl"];
								var businessHours = data["shop"]["businessHours"];
								var minAmount = data["shop"]["minAmount"];
								var address = data["shop"]["address"];
								var range= data["shop"]["range"];
								var introduce=data["shop"]["introduce"];
								var speId=data["speId"];
								var phone=data["shop"]["phone"];
								var mobile=data["shop"]["mobile"];
								var score=data["shop"]["score"];
								var businessStatus=data["shop"]["businessStatus"];
								//var typeIcon=data["shop"]["typeIcon"];
								var memberFlag=data["shop"]["memberFlag"];
								scoreAbleFlag=data["scoreAbleFlag"];
								
								if(introduce=="")
									introduce="暂无";
								
								if(range=="" || range=="0"){
									range="不限";
								}else{
									range=range+"米";
								}
								
								/*if(score=="1"){
									$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
								}else if(score=="2"){
									$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
								}else if(score=="3"){
									$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(2)").addClass("on");
								}else if(score=="4"){
									$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(2)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(3)").addClass("on");
								}else if(score=="5"){
									$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(2)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(3)").addClass("on");
									$("#ldhStoreInfo .store_evaluate i:eq(4)").addClass("on");
								}*/
								
								$("#shopId").val(shopId);
								//$("#business_Status").val(businessStatus);
								
							/*	if(typeIcon=="" || typeIcon.indexOf(".")<0){
									
									typeIcon= ctx+'/v1/img/category_f.png';
								}else{
									
									typeIcon= ctx+'/v1/img/'+typeIcon;
								}*/
								
								$("#shopTypeName").html(data["shop"]["shopTypeName"]);
								//$("#shopTypeIcon").attr("src",typeIcon);
								
								
								if(memberFlag=="" || memberFlag=="0"){
									
									setConcernButton(0);
									
								}else{
									setConcernButton(1);
								}
								
								if(minAmount=="" || minAmount=="0"){
									minAmount="不限";
								}else{
									minAmount=minAmount+"元";
								}
								
								if(businessHours=="" || businessHours=="0"){
									businessHours="不限";
								}
								
								if(businessStatus=="1"){
									
									businessStatus="营业中";
									
									$(".ldh-main-left").css("background-image","url("+ctx+"/v1/img/roof_open.png)");
																		
								}else if(businessStatus=="2"){
									
									businessStatus="休息中";
									
									
									$(".ldh-store-state").css("background-color","#666666");
									
									$(".ldh-main-left").css("background-image","url("+ctx+"/v1/img/roof_close.png)");
									
								}else {
									
									businessStatus="审核中";
									
									$(".ldh-store-state").css("background-color","#666666");
									
									$(".ldh-main-left").css("background-image","url("+ctx+"/v1/img/roof_close.png)");
								}
								
							
								
								if(logoUrl=="" || logoUrl.indexOf(".")<0){
									
									logoUrl= ctx+'/v1/img/category_f.png';
								}else{
									
									logoUrl=fileOpenUrl+logoUrl;
								}
								
								$("#shopName").html(shopName);
								$("#topShopName").html(shopName);
								$("#logoUrl").attr("src",logoUrl);
								$("#topLogoUrl").attr("src",logoUrl);
								//$("#shopSpe").html(base.getSpeHtml(speId));
								$("#shopSpe").html(base.getSpeListHtml(speId));
								$("#introduce").html(introduce);
								if(introduce.length>8){
									$("#topIntroduce").html('<marquee scrollamount=5>'+introduce+'</marquee>');
								}else{
									$("#topIntroduce").html(introduce);
								}
								$("#phone").html(phone);
								//$("#mobile").html(mobile);
								$("#businessHours").html(businessHours);
								$("#range").html(range);
								$("#minAmount").html(minAmount);
								$("#address").html(address);
								
								$("#score").width((score/5)*100+"%");
								$("#businessStatus").html(businessStatus);
								
								
						
								//把title变成商家名称
								document.title="云便利 -"+shopName;
								
							}
							base.cancelLoading();
						

				}))().start();
	};
	

	
	//查询商家商品分类
	exports.getShopMerchandiseType=function(){
		

		var params = {
				shopId : exports.getShopId(),
				parentId:exports.getParentId(),
				sign:MD5(exports.getShopId()+""+exports.getParentId())	
				
		};
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopapp/Shop/shopGoodsType.do", params));
						
						
						if(data["code"]==1){
		
							var htmlStr="";
							
							var length=data["goodsTypeList"].length;
							
							
							
							if(validate.isNull(exports.getParentId())){
								for (var i = 0; i < length; i++) {

									htmlStr += '<li onclick=$ldh_shop.setParentId("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'")><span>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></li>';

								}
								$("#shopMerchandiseTypeList").html(htmlStr);
							}else{
								
								for (var i = 0; i < length; i++) {

									htmlStr += '<li onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></li>';

								}
								
								$("#shopMerchandiseChildTypeList").html(htmlStr);
								
							}
							
							

						}
						
						
					}))().start();
			
	}
	
	//设置商品分类
	var merchandiseTypeName="";
	
	exports.setMerchandiseType=function(id,typeName){
				
		if(validate.isNull(id)){
			
			id=exports.getParentId();
		}
		
		merchandiseTypeId=id;
		
		exports.setCurrentPage(1);
						
		$("#ldhStore .store_neck").removeClass("on");
		
		$("#shopMerchandiseList").html("");
				
		$("#ldhStore .checkmore").hide();
		
		exports.getShopMerchandise();
		
		merchandiseTypeName=typeName;
		
		$("#shopMerchandiseTypeName").html(merchandiseTypeName);
	
	};
	
	// 搜索商家商品
	exports.searchMerchandise=function(){
		
		merchandiseName=$("#merchandiseName").val();
		
		if(merchandiseName=="搜索本店商品"){
			
			return;
		}
		
		exports.setCurrentPage(1);
		
		exports.getShopMerchandise();
		
	};
	
	
	// 获取商家商品
	 exports.getShopMerchandise=function(){
		
		
		var params = {
				shopId : exports.getShopId(),
				goodName:merchandiseName,
				goodType:merchandiseTypeId,
				sort: sort,
				pageSize : pageSize,
				currentPage : exports.getCurrentPage()
		};
		base.showLoading();
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Goods/goodsList.do", params));
						
						
						base.cancelLoading();
						
						if(data["code"]==1){
							
							var htmlStr="";
																	
							for (var i = 0; i < data["goodsList"].length; i++) {
								
											var obj=data["goodsList"][i];
											var unitName=obj["unitName"];
											if(!validate.isNull(obj["unitName"])){
												
												unitName="/"+unitName;
											}
											
											htmlStr += '<li>';
											
											if(validate.isNull(obj["picDefault"])){
												
												htmlStr += '<div class="store_goods_pic"><a rel="external" href="'+ctx+'/h5/merDetail/'+obj["merchandiseId"]+'.shtml"><img src="'+ctx+'/v1/img/default_234_220.png"/></a></div>';

											}else{
																								
												htmlStr += '<div class="store_goods_pic"><a rel="external" href="'+ctx+'/h5/merDetail/'+obj["merchandiseId"]+'.shtml"><img src="'+fileOpenUrl+obj["picDefault"]+'"/></a></div>';
											}
											
											htmlStr += ' <div class="store_goods_info">';
											htmlStr += '<h3  onClick=window.location.href="'+ctx+'/h5/merDetail/'+obj["merchandiseId"]+'.shtml">'+obj["merchandiseName"]+'</h3>';
											htmlStr += '<p class="main_color">¥'+obj["price"].toFixed(2)+unitName+'</p>';
											if(obj["sales"]>0){
												htmlStr += '<p><span>销量：</span><span>'+obj["sales"]+'</span></p>';
											}
											htmlStr += '</div>';
											htmlStr += '<div class="store_goods_addsub" id="'+obj["merchandiseId"]+'">';
											htmlStr += '<button class="btn_sub" data-role="button" data-theme="b" onclick=$ldh_shop.subCartNum("'+obj["merchandiseId"]+'","'+obj["price"].toFixed(2)+'")>-</button>';
											htmlStr += '<span>0</span>';
											htmlStr += '<button class="btn_add" data-role="button" data-theme="b" onclick=$ldh_shop.addCartNum("'+exports.getShopId()+'","'+obj["merchandiseId"]+'","'+obj["price"].toFixed(2)+'")>+</button>';
											htmlStr += '</div>';
											htmlStr += '</li>';
											$("#shopMerchandiseList").append(htmlStr);
											htmlStr="";
											
						   }
							
							var totals=data["totals"];
							var pages=data["pages"];
							
							if(exports.getCurrentPage()<pages){
								$("#ldhStore .checkmore").show();
							}else if(exports.getCurrentPage()==pages && pages>1){
								$("#ldhStore .checkmore").show();
								$("#ldhStore .checkmore").html("已到最后一页");
								$("#ldhStore .checkmore").removeAttr("onclick");
							}
							
							if(totals==0)
							{
								if(validate.isNull(merchandiseName) && validate.isNull(merchandiseTypeName)){
									htmlStr+='<li><p>找不到商品!</p></li>	';

								}else if(!validate.isNull(merchandiseName)){
									htmlStr+='<li><p>亲,抱歉哦！没有找到与“<font color="#ed5d3a!important">'+merchandiseName+'</font>”相关的商品呢!</p></li>	';

								}else if(!validate.isNull(merchandiseTypeName)){
									htmlStr+='<li><p>亲,抱歉哦！没有找到分类为“<font color="#ed5d3a!important">'+merchandiseTypeName+'</font>”的相关商品呢!</p></li>	';
								}
								$("#shopMerchandiseList").html(htmlStr);
								
							}
							
							
						

						}
						
												
						
					}))().start();
	
		
	}
	
	/**
	 * 加载更多
	 */
	exports.loadMoreShopMerchandise=function(){
		
		$("#ldhStore .checkmore").hide();
		
		exports.setCurrentPage(exports.getCurrentPage()+1)
		
		exports.getShopMerchandise();
	}
	
	//根据商家ID查找商家名
	exports.getShopNameById=function(shopId){
		
		var params = {
				shopId:shopId
		};
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Shop/getShopNameById.do", params));

							if(data["code"]==1){
								$("#topShopName").html(data["shopName"]);
							}else{
								
							}
							
		}))().start();
		
		
	}
	
	
	//查询购物车数量
	exports.getCartNum=function(){
			var params = {
			};
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Cart/getCartShopNum.do", params));

								if(data["code"]==1){
									$("#cartNum").html(data["nums"]);
								}else{
									$("#cartNum").html("0");
								}
								
			}))().start();
	};
	
    
	var goodsParams={
			/*"goods[0].merchandiseId":"1111111",
			"goods[0].nums":"1",
			"goods[1].merchandiseId":"222222",
			"goods[1].nums":"2"*/
	};
	
	function count(o){
        var t = typeof o;
        if(t == 'string'){
                return o.length;
        }else if(t == 'object'){
                var n = 0;
                for(var i in o){
                        n++;
                }
                return n/2;
        }
        return false;
   }
	
	
	//delete goodsParams["merchandiseId[0]"];


	
	//添加商品到购物车
	exports.addCartNum=function(shopId,merchandiseId,price){
		
		
		//goodsParams[0].merchandiseId=merchandiseId;
		//goodsParams[0].nums=1;
		
		$("#"+merchandiseId+" .btn_sub").show();
		
		$("#"+merchandiseId+" span").show();

		$("#"+merchandiseId+" span").html(parseInt($("#"+merchandiseId+" span").text())+1);
		
		$("#ldhStore .store_goods_btm em:eq(1)").html(parseInt($("#ldhStore .store_goods_btm em:eq(1)").text())+1);
		
		$("#ldhStore .store_goods_btm em:eq(0)").html((Number($("#ldhStore .store_goods_btm em:eq(0)").text())+Number(price)).toFixed(2));
		
		
		var length=count(goodsParams);
		if(length==0){
			goodsParams["goods[0].merchandiseId"]=merchandiseId;
			goodsParams["goods[0].nums"]=1;
		}else{
			var n=0,c_n=0,exit=false;
			for(var p in goodsParams){
				
				if(goodsParams[p]==merchandiseId){
					
					exit=true;
					c_n=n;
				}
				n++;
			}
			if(exit){
				c_n=c_n/2;
				goodsParams["goods["+c_n+"].merchandiseId"]=merchandiseId;
				goodsParams["goods["+c_n+"].nums"]=$("#"+merchandiseId+" span").text();
			}else{

				goodsParams["goods["+length+"].merchandiseId"]=merchandiseId;
				goodsParams["goods["+length+"].nums"]=$("#"+merchandiseId+" span").text();
			}
		}
		
		for(var p in goodsParams){
			
			//alert(p+":"+goodsParams[p]);
		}
	
		
	};
	
	
	//在购物车删除商品
	exports.subCartNum=function(merchandiseId,price){
		
		$("#"+merchandiseId+" span").html(parseInt($("#"+merchandiseId+" span").text())-1);

		if($("#"+merchandiseId+" span").text()=="0"){
			$("#"+merchandiseId+" .btn_sub").hide();
			$("#"+merchandiseId+" span").hide();
			
		}
		
		$("#ldhStore .store_goods_btm em:eq(1)").html(parseInt($("#ldhStore .store_goods_btm em:eq(1)").text())-1);
		
		$("#ldhStore .store_goods_btm em:eq(0)").html((Number($("#ldhStore .store_goods_btm em:eq(0)").text())-Number(price)).toFixed(2));
		
		
	
			var n=0,c_n=0,isDelete=false;
			
			for(var p in goodsParams){
				
				if(goodsParams[p]==merchandiseId){
					
					if($("#"+merchandiseId+" span").text()=="0"){
						
						
						isDelete=true;
					}
					
					c_n=n;
				}
				n++;
			}
			c_n=c_n/2;
			//当num=0时，这个属性已经删除了。所以不需要重新赋值
			if(!isDelete){
				goodsParams["goods["+c_n+"].merchandiseId"]=merchandiseId;
				goodsParams["goods["+c_n+"].nums"]=$("#"+merchandiseId+" span").text();
			}else{
				delete goodsParams["goods["+c_n+"].merchandiseId"];
				delete goodsParams["goods["+c_n+"].nums"];
			}
			var _goodsParams={};
			var d_n=0,d_c_n=0;
			for(var p in goodsParams){
				
				if(d_n%2==0){
					
					_goodsParams["goods["+d_c_n+"].merchandiseId"]=goodsParams[p];

				}else{
					_goodsParams["goods["+d_c_n+"].nums"]=goodsParams[p];
					d_c_n++;
				}
				d_n++;
			}
			
			goodsParams=_goodsParams;
			
			/*for(var p in goodsParams){
				
				alert(p+":"+goodsParams[p]);
			}*/
	};
	
	var clickable=true;
	exports.addCart=function(){
		
		
		
		
		if(count(goodsParams)==0){
			
			showTips("请选择商品");	
			return;
		}
		
		if(validate.isNull(base.getCookie("userId"))){
			showTips("请先登录");	
			//base.showDiv("#ldhLogin","","?shopId="+exports.getShopId()+"&fromPage=ldhStore");
			window.location.href=ctx+"/h5/login.shtml?shopId="+exports.getShopId()+"&fromPage=ldhStore";
			return;
		}
		
		if(!clickable){
			return;
		}
		
		clickable=false;
		
		base.showLoading();
		
		goodsParams["type"]=0;
		goodsParams["userId"]=base.getCookie("userId");
		goodsParams["loginSign"]=$ldh_base.getCookie("loginSign");
		goodsParams["sign"]=MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId")+"0");
		
		
		eval(
				Wind.compile("async", function() {
		
					var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Cart/addshoptoCart.do", goodsParams));
		
							if(data["code"]==1){
								
								//$("#cartNum").html(parseInt($("#cartNum").html())+1);
								
								//alert(data["message"]);
								//showTips("请选择商品");	
								$("#ldhStore .store_goods_addsub span").html("0");
								$("#ldhStore .store_goods_addsub span").hide();
								$("#ldhStore .store_goods_addsub .btn_sub").hide();
								$("#ldhStore .store_goods_btm em:eq(0)").html("0");
								$("#ldhStore .store_goods_btm em:eq(1)").html("0");
								goodsParams={};
								//base.showDiv("#ldhCart");
								window.location.href=ctx+"/h5/cart.shtml";
							}else if(data["code"]=="-4444"){
								
								window.location.href=ctx+"/h5/login.shtml?shopId="+exports.getShopId()+"&fromPage=ldhStore";
								
							}else{
								
								showTips(data["message"]);	
							}
							
							clickable=true;
							base.cancelLoading();
							
		}))().start();
		
		
	}
	
	//查询商品详情
	exports.loadMerchandiseDetail=function(position,merchandiseId){
		
		exports.prodetailsShow();
		
		$("#div_merchandise_detail").html(' <div class="ldh-waiting"></div> <div class="ldh-productdetails-close" onclick="$ldh_shop.prodetailsHide()">&nbsp;</div>');
  
		var params = {
				shopId : exports.getShopId(),
				merchandiseId:merchandiseId
		};
		
		
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Goods/queryDetails.do", params));
					
					var htmlStr="";
					if(data["code"]==1){
						
						var picDefault=data.details.picDefault;
						
						if(picDefault=="" || picDefault.indexOf(".")<0){
							
							picDefault= ctx+"/v1/img/default_234_220.png";
						}else{
							
							picDefault=fileOpenUrl+data.details.picDefault;
						}
																
										htmlStr += '<div class="ldh-prodts-l">';
										htmlStr += '<div class="ldh-productpic">';
										htmlStr += '<img id="picDefault" src="'+picDefault+'">';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-productbtn">';
										htmlStr += '<div class="ldh-productbtn-l"></div>';
										htmlStr += '<div class="ldh-productbtn-r"></div>';
										htmlStr += '<div class="ldh-productbtn-pic" style="width: 366px;">';
										htmlStr += '<ul style="width: 488px; left: 0px;" id="smallImageList">';
										for(var i =0;i<data.images.length;i++){
											
											var img_small=data.images[i].imgUrl,img_big="";
											
											if(validate.isNull(img_small)){
												
												img_small=ctx+"/v1/img/default_234_220.png";
												
												img_big=img_small;
												
											}else{
												
												img_big=fileOpenSourceUrl+img_small;
												
												img_small=fileOpenUrl+img_small;
												
												
											}
											
											if(i==0){
												htmlStr += '<li class="ware_pic_hover" onclick=$ldh_shop.switchImage(this,"'+img_big+'")><img width="55" height="55" src="'+img_small+'"></li>';
											}else{
												htmlStr += '<li onclick=$ldh_shop.switchImage(this,"'+img_big+'")><img width="55" height="55" src="'+img_small+'"></li>';
											}
										}
										htmlStr += '</ul>';
										htmlStr += '</div>';
										htmlStr += '</div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-prodts-r">';
										htmlStr += '<div class="ldh-prodts-title">';
										htmlStr += '<h3 id="">'+data["details"]["merchandiseName"]+'</h3>';
										htmlStr += '<p>'+data["details"]["brief"]+'</p>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-prodts-info clearfix">';
										htmlStr += '<div class="fl-left">';
										var unitName=data["details"]["unitName"];
										if(!validate.isNull(unitName)){
											
											unitName="/"+unitName;
										}
										htmlStr += '<p><span>邻店价：</span><span class="color-main">¥'+data["details"]["price"].toFixed(2)+unitName+'</span></p>';
										if(data["details"]["price"]<data["details"]["mktprice"]){
											htmlStr += '<p><span>原价：</span><s>¥'+data["details"]["mktprice"].toFixed(2)+unitName+'</s></p>';
										}
										htmlStr += '</div>';
									//	htmlStr += '<div class="fl-right"><button type="button" class="ldh-goods-sub"></button><button type="button" class="ldh-goods-add"></button></div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-prodts-btn"><p class="color-main" id="tip_add_cartnum" style="display:none;">加入购物车成功</p><br><button type="button" class="btn-green" onclick=$ldh_cart.addCartNum(this,1,"'+exports.getShopId()+'","'+data["details"]["merchandiseId"]+'","'+data["details"]["price"]+'",'+exports.getCurrentPage()+position+')>加入购物车</button></div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-productdetails-close" onclick="$ldh_shop.prodetailsHide()">&nbsp;</div>';
				    
										
					}
				
					$("#div_merchandise_detail").html(htmlStr);
					
					propicRoll();
					
				}))().start();

		
	};
	

	
	//切换图片
	exports.switchImage=function(obj,url){
		
		$("#smallImageList li").removeClass("ware_pic_hover");
		
		$(obj).addClass("ware_pic_hover");
		
		$("#picDefault").attr("src",url);
		
	};
	
	// 商品详情隐藏
	exports.prodetailsHide=function(){
		$(".ldh-productdetails-bg").hide();	
	};
	
	
	//商品详情出现
	exports.prodetailsShow=function(){
		
		$(".ldh-productdetails-bg").show();	
	};
	
	
	var clickable=true;
	
	//收藏商家
	exports.concernShop=function(){
		
		if(!clickable)
		{
			return;
		}
		
		clickable=false;
		
		$("#btn_favor em").html("");
		
		base.showLoading("#btn_favor em",26);
		
		var params = {
				shopId : exports.getShopId()
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Shop/concernShop.do", params));
						
						base.cancelLoading("#btn_favor em");
						
						clickable=true;
						
						if(!base.validateLoginStatus(data)){
							setConcernButton(0);
							return;
						}
						
						if(data["code"]==1){
							
							setConcernButton(1);
							
						}else if(data["code"]=="-10001"){
							alert(data["message"]);
						}
						
		}))().start();
			
	};
	
	//取消收藏商家
	exports.cancleConcernShop=function(){

		if(!clickable)
		{
			return;
		}
		
		clickable=false;
		
		$("#btn_favor em").html("");
		
		base.showLoading("#btn_favor em",26);
		
		var params = {
				shopId : exports.getShopId()
		};
		
		eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Shop/cancleConcernShop.do", params));
						
						if(!base.validateLoginStatus(data)){
							setConcernButton(1);
							return;
						}
						
						if(data["code"]==1){
							setConcernButton(0);
						}else if(data["code"]=="-10001"){
							alert(data["message"]);
						}
						base.cancelLoading("#btn_favor em");
						clickable=true;
		}))().start();
			
	};
	
	//设置收藏按钮的样式和状态
	function setConcernButton(status){
		
		if(status==1){
			//已收藏
			$("#btn_favor").css("width","54px");
			$("#btn_favor").css("background","#ed5d3a");
			$("#btn_favor").html('<em onclick="$ldh_shop.cancleConcernShop()">已收藏</em>');
			
		}else{
			//未收藏
			$("#btn_favor").css("width","48px");
			$("#btn_favor").css("background","#CC0");
			$("#btn_favor").html('<em onclick="$ldh_shop.concernShop()">收藏</em>');
			
		}
		
	}
	
	
	//商家评分
	exports.setShopScore=function(score){

		if(!scoreAbleFlag){
			
			showTips("需要在本店消费过才能评分哦");
			return;
		}
		
		base.showLoading();
		
		if(score=="1"){
			$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
		}else if(score=="2"){
			$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
		}else if(score=="3"){
			$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(2)").addClass("on");
		}else if(score=="4"){
			$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(2)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(3)").addClass("on");
		}else if(score=="5"){
			$("#ldhStoreInfo .store_evaluate i:eq(0)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(1)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(2)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(3)").addClass("on");
			$("#ldhStoreInfo .store_evaluate i:eq(4)").addClass("on");
		}
		var params = {
				score:score,
				shopId : exports.getShopId(),
				userId:$ldh_base.getCookie("userId"),
				"loginSign":$ldh_base.getCookie("loginSign"),
				"sign":MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId")+exports.getShopId()+score)
		};
		
		eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopapp/ShopRecGoods/scoreShop.do", params));
	
						base.cancelLoading();
						
						if(data["code"]==1){
							showTips("评分成功");
						}else if(data["code"]=="-10001"){
							
							showTips("请登录再评分");
						}else{
							
							showTips(data.message);
						}
						$("#ldhStoreInfo .store_evaluate i").removeClass("on");
						
		}))().start();
			
	};
	
});

